<template>
  <div class="view_page userList">
    <el-card class="box-card">
      <!--卡片头部-->
      <div slot="header" class="clearfix">
        <!--左侧-->
        <div class="left">
          <div class="menu-title">
            设备列表
          </div>
        </div>
        <!--右侧-->
        <div class="right">
          <!--          <el-button type="primary" size="small" @click="navtoAdd('add')"-->
          <!--            >新增-->
          <!--          </el-button>-->
        </div>
      </div>
      <!-- 卡片内容 -->
      <div>
        <!--筛选-->
        <div class="query-operate">
          <el-form
            class="demo-form-inline indoor-scene-buzhou-list-form"
            :inline="true"
            :model="TESTFROMDATA"
            @submit.native.prevent
          >
            <el-form-item
              label="设备类型"
              label-width="120px"
              style="margin-top: 5px; margin-bottom: 5px;"
            >
              <el-select v-model="state" @change="changetype()">
                <el-option
                  v-for="item in stateList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item
              label="设备名称"
              label-width="120px"
              style="margin-top: 5px; margin-bottom: 5px;"
            >
              <el-input
                clearable
                @clear="searchList"
                v-model="TESTFROMDATA.title"
                placeholder="请输入设备名称"
                @keyup.native.enter="searchList()"
              ></el-input>
            </el-form-item>

            <el-form-item
              style="margin-top: 5px; margin-bottom: 5px;margin-left: 10px;"
            >
              <el-button type="primary" @click="searchList()">查询</el-button>
            </el-form-item>
          </el-form>
        </div>
        <el-table :data="datalist" style="width: 100%">
          <!-- <el-table-column prop="id" label="ID" align="center" min-width="50">
          </el-table-column> -->
          <el-table-column prop="id" label="序号" align="center" min-width="50">
            <template slot-scope="scope">
              <div>
                {{ (pageNum - 1) * size + (scope.$index + 1) }}
              </div>
            </template>
          </el-table-column>
          <el-table-column
            prop="name"
            label="设备名称"
            align="center"
            min-width="140"
          >
          </el-table-column>
          <el-table-column
            prop="equipment_type_name"
            label="设备类型"
            align="center"
            min-width="100"
          >
          </el-table-column>
          <el-table-column
            prop="reservoir"
            label="所属水库"
            align="center"
            min-width="100"
          >
          </el-table-column>
          <el-table-column
            prop="cover_id_url"
            label="封面图"
            align="center"
            min-width="100"
          >
            <template slot-scope="scope">
              <img
                v-if="scope.row.cover_id_url != ''"
                :src="scope.row.cover_id_url"
                alt=""
                width="80px"
                height="80px"
                style="object-fit: cover;"
              />
              <img
                v-else
                src="https://dongping.jnaw.top/dongping_static/defaultImg.png"
                alt=""
                width="80px"
                height="80px"
                style="object-fit: cover;"
              />
            </template>
          </el-table-column>
          <el-table-column
            prop="it_code"
            label="设备编号"
            align="center"
            min-width="80"
          >
          </el-table-column>
          <el-table-column
            prop="it_number"
            label="设备型号"
            align="center"
            min-width="120"
          >
          </el-table-column>
          <!-- <el-table-column
            prop="state"
            label="设备状态"
            align="center"
            min-width="100"
          >
          </el-table-column> -->
          <el-table-column
            prop="state"
            label="设备状态"
            align="center"
            min-width="100"
          >
            <template slot-scope="scope">
              <div>
                {{ is_state(scope.row.state) }}
              </div>
            </template>
          </el-table-column>
          <!-- <el-table-column
            prop="river_type"
            label="河流类型"
            align="center"
            min-width="80"
          >
            <template slot-scope="scope">
              <div>
                {{ approvalstate(scope.row.river_type) }}
              </div>
            </template>
          </el-table-column>
          <el-table-column
            prop="river_name"
            label="河流/水库/坑塘名称"
            align="center"
            min-width="160"
          >
          </el-table-column> -->
          <!-- <el-table-column
            prop="install_position"
            label="安装位置"
            align="center"
            min-width="140"
          >
          </el-table-column> -->
          <el-table-column
            prop="install_position"
            label="安装位置"
            align="center"
            min-width="220"
          >
            <template slot-scope="scope">
              <div>
                {{ addressData(scope.row.install_position) }}
              </div>
            </template>
          </el-table-column>
          <el-table-column
            prop="use_time"
            label="投运时间"
            align="center"
            min-width="100"
          >
          </el-table-column>
          <el-table-column
            prop="responsible_2"
            label="设备负责人"
            align="center"
            min-width="100"
          >
          </el-table-column>
          <el-table-column
            prop="responsible_phone_2"
            label="责任人联系方式"
            align="center"
            min-width="120"
          >
          </el-table-column>
          <el-table-column
            prop="manufacturer"
            label="生产厂家"
            align="center"
            min-width="120"
          >
          </el-table-column>
          <el-table-column
            prop="buy_time"
            label="购买时间"
            align="center"
            min-width="100"
          >
          </el-table-column>
          <el-table-column
            prop="validity_period"
            label="质保期限"
            align="center"
            min-width="100"
          >
          </el-table-column>
          <el-table-column
            prop="longitude"
            label="经度"
            align="center"
            min-width="100"
          >
          </el-table-column>
          <el-table-column
            prop="latitude"
            label="纬度"
            align="center"
            min-width="100"
          >
          </el-table-column>
          <el-table-column
            prop="take_height"
            label="高度"
            align="center"
            min-width="100"
          >
          </el-table-column>
          <el-table-column
            prop="camera"
            label="监控"
            align="center"
            min-width="70"
            fixed="right"
          >
            <template slot-scope="scope">
              <el-button
                type="primary"
                size="small"
              >绑定
              </el-button>
            </template>
          </el-table-column>
          <el-table-column
            fixed="right"
            label="操作"
            min-width="290"
            align="center"
          >
            <template slot-scope="scope">
              <div style="display: flex;align-items: center;flex-wrap: wrap; ">

                <el-button
                  type="primary"
                  size="small"
                  @click="tipMeasurePointPage(scope.row)"
                >测点
                </el-button>
                <el-button
                  type="primary"
                  size="small"
                  @click="navtoAdd('update', scope.row.id)"
                >修改
                </el-button>
                <el-button
                  type="primary"
                  size="small"
                  @click="navto3D(scope.row.id)"
                >3D模型
                </el-button>
                <el-button type="danger" size="small" @click="del(scope.row)"
                >删除
                </el-button>
              </div>
            </template>
          </el-table-column>
        </el-table>
        <!--分页-->
        <pagination
          :total="total"
          :currentPage="pageNum"
          :pageSize="size"
          position="right"
          @search="searchPagination"
        >
        </pagination>
      </div>
    </el-card>
  </div>
</template>

<script>
import axios from "axios";
import qs from "qs";
import {Message} from "element-ui";
import pagination from "@/components/common/pagination/pagination";
import devConfig from "*/dev.config";

export default {
  components: {
    pagination
  },
  watch: {},
  data() {
    return {
      // userInfo: this.$apis.getqxbutton("设备列表"),
      // userInfo_id: JSON.parse(
      //   localStorage.getItem(this.$apis.getLocalKey().loginPersonnelInformation)
      // ).data.id,
      // 筛选内容
      TESTFROMDATA: {
        title: ""
      },
      // 状态
      state: -1,
      stateList: [
        {
          id: -1,
          name: "全部"
        }
      ],

      // 列表的数据
      datalist: [
        {
          longitude: '36.2354323',
          latitude: '102.24364334',
          take_height: '122',
          reservoir: "马河水库",
          "buy_time": "2023-03-27 12:00:00",
          "cover_id": 5884,
          "cover_id_name": "WechatIMG1239.jpeg",
          "cover_id_url": "https://dongpingcdn.jnaw.top/2023061410593933.jpeg",
          "equipment_type": 1,
          "equipment_type_name": "水位计",
          "id": 23,
          "install_position": "{\"url\":\"https://mapapi.qq.com/web/mapComponents/locationPicker/v/index.html?search=1&type=1&key=CYQBZ-VGPK4-7JKUQ-XPE3E-SSN3H-EXFVJ&referer=app name\",\"lng\":\"116.407825\",\"lat\":\"35.932687\",\"address\":\"山东省泰安市东平县济广高速公路\",\"poiname\":\"东平互通西300米(济广高速公路西)\"}",
          "instantaneous_flow": "-",
          "it_code": "CY-WL66A",
          "it_number": "CY-WL66A",
          "it_qr": 64,
          "it_qr_name": "占位图.jpg",
          "it_qr_url": "https://dongpingcdn.jnaw.top/2022121609150839.jpg",
          "liquid_height": "-",
          "manufacturer": "深圳大荣智能科技有限公司",
          "name": "湿地橡胶坝水位计",
          "nfc_code": "",
          "point_array": [],
          "responsible_1": "",
          "responsible_2": "",
          "responsible_phone_2": "",
          "river_id": 1,
          "river_name": "大汶河",
          "river_type": 1,
          "state": "0",
          "type": 1,
          "unityInfo": {
            "cameraRotationX": "0",
            "cameraRotationY": "0",
            "equipment": 23,
            "focusingDistance": "30",
            "focusingX": "0",
            "focusingY": "30",
            "id": 361,
            "modelId": "",
            "posX": "442.1797",
            "posY": "2.280001",
            "posZ": "434.0748",
            "remark": "",
            "thumbnailPath": "",
            "type": 4
          },
          "use_time": "2023-03-27 12:00:00",
          "validity_period": "2024-03-27 12:00:00"
        },
      ],
      pageNum: 1,
      page: 1,
      size: 10,
      total: 0,
    };
  },
  created() {
    this.page = localStorage.getItem("page");
    this.getstateList();
    // this.getListPage();
  },
  mounted() {
  },
  methods: {
    tipMeasurePointPage(item) {
      this.$router.push({
        path: "/admin/equipmentAccount/measurePointList",
        query: {
          type: item
        }
      });
    },
    is_state(item) {
      //  state 0 正常 1 异常 2 故障
      if (item == 0) {
        return "正常";
      } else if (item == 1) {
        return "异常";
      } else if (item == 2) {
        return "故障";
      }
    },
    //河流类型
    approvalstate(item) {
      switch (item) {
        case 1:
          return "河流";
          break;
        case 2:
          return "水库";
          break;
        case 3:
          return "坑塘";
          break;
        default:
          break;
      }
    },
    addressData(item) {
      // console.log("item:", item);
      // if (item != null || item != "") {
      //   var data = JSON.parse(item);
      //   return data;
      // } else {
      //   return "123";
      // }
      if (item == null || item == "") {
        return "";
      } else {
        var data = JSON.parse(item);
        return data.poiname;
      }
    },
    //切换状态
    changetype() {
      var _this = this;
      _this.page = 1;
      _this.getListPage();
    },
    getstateList() {
      var _this = this;
      var datas = {
        page: _this.page,
        size: 999
      };
      _this.$apis.equipment_type_list(datas).then(res => {
        if (res.result == 0) {
          // _this.stateList = [];
          _this.stateList = [
            {
              id: -1,
              name: "全部"
            }
          ];
          for (let i = 0; i < res.data.length; i++) {
            _this.stateList.push(res.data[i]);
          }
          _this.getListPage();
        }
      });
    },
    //查询列表
    getListPage() {
      var _this = this;
      var datas = {
        equipment_type: this.state,
        name: _this.TESTFROMDATA.title,
        page: _this.page,
        size: _this.size
      };
      _this.$apis.equipment_list(datas).then(res => {
        if (res.result == 0) {
          _this.datalist = res.data;
          _this.total = res.rows;
          _this.pageNum = res.page;
        }
      });
    },
    //模糊查询
    searchList() {
      this.page = 1;
      this.datalist = [];
      this.getListPage();
    },
    //分页
    searchPagination(page) {
      this.page = page;
      localStorage.setItem("page", page);
      this.getListPage();
    },
    // 跳转详情
    lookfiles(item) {
      var _this = this;
      var datas = {
        id: item
      };
      _this.$apis.equipment_query(datas).then(res => {
        if (res.result == 0) {
          _this.$router.push({
            path: "/admin/equipmentAccount/equipmentAccountDetial",
            query: {
              data: res.data
            }
          });
        }
      });
    },
    //跳转新增
    navtoAdd(type, item) {
      var _this = this;
      if (type == "add") {
        _this.$router.push({
          path: "/admin/equipmentAccount/equipmentAccountAdd",
          query: {
            type: type
          }
        });
      } else {
        var datas = {
          id: item
        };
        _this.$apis.equipment_query(datas).then(res => {
          if (res.result == 0) {
            _this.$router.push({
              path: "/admin/equipmentAccount/equipmentAccountAdd",
              query: {
                type: type,
                // data: res.data
                data: JSON.stringify(res.data)
              }
            });
          }
        });
      }
    },
    navto3D(item) {
      var _this = this;
      _this.$router.push({
        path: "/admin/equipmentAccount/modelMassage",
        query: {
          type: item
        }
      });
    },
    del(item) {
      var _this = this;
      var datas = {
        id: item.id
      };
      _this
        .$confirm("确定要删除【" + item.name + "】吗?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
        .then(() => {
          _this.$apis.equipment_del(datas).then(res => {
            if (res.result == 0) {
              Message.success("删除成功");
              if (_this.page > 1 && _this.datalist.length <= 1) {
                _this.page = _this.page - 1;
              }
              _this.getListPage();
            }
          });
        })
        .catch(() => {
        });
    },
    download() {
      window.open("https://xiaoyoushengxue.com/2022051218194530.xlsx");
    },
    downloaddata() {
      var _this = this;

      window.open(
        devConfig.apiPrefix +
        "/excel/user_all_export?user_role=" +
        _this.TESTFROMDATA.type
      );
    }
  }
};
</script>

<style>
.el-table .cell {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: normal !important;
}
</style>
